//
//  TZBaseNavC.swift
//  SimpleTZ
//
//  Created by wangfeng on 2020/7/9.
//  Copyright © 2020 davis. All rights reserved.
//

/*
 包含全局返回手势
 **/

import UIKit

class TZBaseNavC: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
//        navigationBar.setBackgroundImage(ImageWithColor(color:UIColorFromRGB(R: 7, G: 113, B: 197)!), for: UIBarMetrics.default)
        
//        navigationBar.isOpaque = true
//        navigationBar.isTranslucent = false
        // Do any additional setup after loading the view.
        
        
        if self.responds(to: #selector(getter: interactivePopGestureRecognizer)){
            self.interactivePopGestureRecognizer?.delegate = self;
        }
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if self.responds(to: #selector(getter: interactivePopGestureRecognizer)){
            self.interactivePopGestureRecognizer?.isEnabled = false;
        }
        super .pushViewController(viewController, animated: animated)
    }
    
    
}
    


// MARK: -Delegate
extension TZBaseNavC : UINavigationControllerDelegate,UIGestureRecognizerDelegate{
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        if navigationController.responds(to: #selector(getter: interactivePopGestureRecognizer)) {
            navigationController.interactivePopGestureRecognizer?.isEnabled = true
        }
        
        
        if navigationController.viewControllers.count == 1 {
            navigationController.interactivePopGestureRecognizer?.isEnabled = false
            navigationController.interactivePopGestureRecognizer?.delegate = nil
        }
    }
}
